LIBRARY IEEE; 
USE IEEE.STD_LOGIC_1164.ALL;
USE IEEE.STD_LOGIC_ARITH.ALL;
USE IEEE.STD_LOGIC_UNSIGNED.ALL;

-- SYNCHRONOUS 4-BIT COUNTERS

ENTITY ic_8 IS

    PORT(clear, pin1, pin2, pin3, pin4, pin5, pin6, pin7, pin9, pin10: IN STD_LOGIC := '0'; 
        pin11, pin12, pin13, pin14, pin15: OUT STD_LOGIC := '0');

END ic_8;

ARCHITECTURE bit4_counter_ic OF ic_8 IS

SIGNAL COUNT: STD_LOGIC_VECTOR(3 DOWNTO 0) := "0000";

BEGIN

    pin14 <= COUNT(0);
    pin13 <= COUNT(1);
    pin12 <= COUNT(2);
    pin11 <= COUNT(3);

    PROCESS(pin1, pin2, pin3, pin4, pin5, pin6, pin7, pin9, pin10)
    BEGIN
        IF(pin2 = '1' AND pin2'EVENT) THEN
            IF(pin1 = '0' OR clear = '1') THEN
                COUNT <= "0000";
				ELSIF(pin9 = '0') THEN
                COUNT(0) <= pin3;
                COUNT(1) <= pin4;
                COUNT(2) <= pin5;
                COUNT(3) <= pin6;
            ELSIF(pin7 = '1') THEN
                COUNT <= COUNT + "0001";
			ELSE
                COUNT <= COUNT;
            END IF;
        END IF;
    END PROCESS;
	 
    PROCESS(COUNT)
    BEGIN
        IF(COUNT = "1111" AND pin10 = '1')THEN
            pin15 <= '1';
        ELSE
            pin15 <= '0';
        END IF;
    END PROCESS;

END bit4_counter_ic;